package com.dqp.cslggroup.Features;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.dqp.cslggroup.Api.appApi;
import com.dqp.cslggroup.EventBus.MessageEvent;
import com.dqp.cslggroup.R;
import com.dqp.cslggroup.UI.BaseActivity;
import com.dqp.cslggroup.Util.UiUtils;
import com.dqp.cslggroup.bean.Club;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.ArrayList;


public class GradeExamination extends BaseActivity {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.test);
        EventBus.getDefault().register(this);
        selLoginImg("exam");
    }

    @SuppressLint("HandlerLeak")
    public void selLoginImg(String stype) {
        new Thread(() -> {
            Club club;
            ArrayList<Club> dataList = appApi.getLoginImg();
            for (int i = 0; i < dataList.size(); i++) {
                club = dataList.get(i);
                if (club.getClub_des().equals(stype)) {
                    EventBus.getDefault().post(new MessageEvent("GradeExamination", 1, club));
                }
            }

        }).start();
    }

    public void web(View v) {
        switch (v.getId()) {
            case R.id.cet_test:
                Intent intent = new Intent(GradeExamination.this, CET.class);
                startActivity(intent);
                break;
            case R.id.ncre:
                UiUtils.openBrowser(this, "http://ncre.neea.edu.cn/");
                break;
            case R.id.teacher_test:
                UiUtils.openBrowser(this, "http://ntce.neea.edu.cn/");
                break;
            case R.id.tcefl:
                UiUtils.openBrowser(this, "http://toefl-main.neea.cn/");
                break;
            case R.id.ielts:
                UiUtils.openBrowser(this, "http://ielts-main.neea.cn/");
                break;
            case R.id.testdaf:
                UiUtils.openBrowser(this, "http://testdaf-main.neea.cn/");
                break;
            case R.id.jlpt:
                UiUtils.openBrowser(this, "http://jlpt-main.neea.cn/");
                break;
            case R.id.topik:
                UiUtils.openBrowser(this, "http://topik-main.neea.cn/");
                break;
            case R.id.yjs:
                UiUtils.openBrowser(this, "https://yz.chsi.com.cn/");
                break;
            case R.id.pth:
                UiUtils.openBrowser(this, "http://www.cltt.org/studentscore");
                break;


        }
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }

    @SuppressLint("SetTextI18n")
    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMessageEvent(MessageEvent event) {
        if (event.getEvent().equals("GradeExamination")) {
            if (event.getWhat() == 1) {
                ImageView bg = findViewById(R.id.test_img);
                TextView title = findViewById(R.id.test_img_title);
                Club club = (Club) event.getObj();
                title.setText(club.getClub_name());
                Glide.with(GradeExamination.this).load(club.getClub_img()).into(bg);
            }
        }
    }
}
